﻿
using Teamwish.Domain.IBLL;
using Teamwish.Domain.Models;
using System.Linq;
using Teamwish.Domain.BLL;

namespace Domain.BLL
{
    public class UserinfoBLL:BaseBLL<Userinfo>,IUserinfoBLL
    {
        protected EfDbContext context;
        public UserinfoBLL(EfDbContext context) : base(context)
        {
            this.context = context;
        }
        //其他业务

        //public IList<Ad> GetPositionAdsFromCache(int positionId, Platform platform)
        //{
        //    string cacheKey = string.Format("ad-{0}-{1}", positionId, (int)platform);
        //    var list = HttpContext.Current.Cache[cacheKey] as IList<Ad>;
        //    if (list == null)
        //    {
        //        lock (ad_obj)
        //        {
        //            list = HttpContext.Current.Cache[cacheKey] as IList<Ad>;
        //            if (list == null)
        //            {
        //                list = db.Ad.Where(p=>p.Platform== platform).ToList();
        //                HttpContext.Current.Cache.Insert(cacheKey, list, null, DateTime.UtcNow.AddMinutes(10), System.Web.Caching.Cache.NoSlidingExpiration);
        //            }
        //        }
        //    }
        //    return list;
        //}

        public bool Login(string username, string pwd)
        {
            string pwd1 = Teamwish.Utilities.Md5Helper.MD5(pwd,32);
            return context.Userinfo.Any(p => p.Username == username && p.Password == pwd1);
        }

        ////操作类方法（增删改）
        //public bool InsertByDefault(Userinfo userinfo)
        //{
        //    userinfo.Name = userinfo.Name.Trim();
        //    userinfo.CreateDate = DateTime.Now;
        //    context.Userinfo.Add(userinfo);
        //    return context.SaveChanges() > 0;
        //}

        //public bool UpdateByManager(Userinfo userinfo)
        //{

        //    bool result = false;
        //    Userinfo existing = context.Userinfo.Find(userinfo.Id);
        //    if (existing != null)
        //    {
        //        context.Entry(existing).CurrentValues.SetValues(userinfo);
        //        result = context.SaveChanges() > 0;
        //    }
        //    return result;
        //}

        //public bool DeleteByLogic(object id)
        //{
        //    Userinfo obj = context.Userinfo.Find(id);
        //    if (obj != null)
        //    {
        //        obj.State = 0;
        //        return context.SaveChanges() > 0;
        //    }            
        //    return true;
        //}

    }
}
